from fastapi import FastAPI
import uvicorn
from fastapi.middleware.cors import CORSMiddleware
from questionnaire import distributeTaskAPI
from questionnaire import questionnaireAPI
from user import userAPI
from user import userGroupAPI
from util import fileAPI

app = FastAPI()

# 2、声明一个源列表；重点：要包含跨域的客户端 源
origins = [
    "*",
]

# 3、配置 CORSMiddleware
app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,  # 允许访问的源
    allow_credentials=True,  # 支持 cookie
    allow_methods=["*"],  # 允许使用的请求方法
    allow_headers=["*"]  # 允许携带的 Headers
)

app.include_router(questionnaireAPI.app, prefix="/questionnaire", tags=["questionnaireAPI"])
app.include_router(distributeTaskAPI.app, prefix="/distributeTask", tags=["distributeTaskAPI"])
app.include_router(userAPI.app, prefix="/user", tags=["userAPI"])
app.include_router(userGroupAPI.app, prefix="/user", tags=["userGroupAPI"])
app.include_router(fileAPI.app, prefix="/file", tags=["fileAPI"])

if __name__ == "__main__":
    uvicorn.run(app='server:app', host="0.0.0.0", port=8000, reload=False)
